package com.whfp.coky.api

import com.google.gson.Gson
import com.tencent.mmkv.MMKV
import com.whfp.coky.other.Constants
import com.whfp.coky.utils.LogUtil
import okhttp3.MediaType
import okhttp3.RequestBody
import java.text.SimpleDateFormat
import java.util.*

/**
 * 可以废弃，在api中可以直接传map
 * *
 * created by coky on 2022/3/28
 */
class RequestBodyBuild {
    companion object{
        fun buildBodyByMap(map: HashMap<String,String>):RequestBody{
            LogUtil.e("gson..parse map...${Gson().toJson(map)}")
            return RequestBody.create(
                MediaType.parse("application/json; charset=utf-8"),
                Gson().toJson(map));
        }

        /**
         * 构造本地唯一识别
         */
        fun buildPhoneMac(): String {
            var phoneMac = MMKV.defaultMMKV().getString(Constants.PHONE_MAC, "")
            if (phoneMac.isNullOrEmpty()) {
                phoneMac = SimpleDateFormat("yyyyMMddHHmmssSSS").format(Date())
                MMKV.defaultMMKV().putString(Constants.PHONE_MAC,phoneMac)
            }
            return phoneMac!!
        }

    }
}